//
//  TheBestHotTVCollectionViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/13.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "TheBestHotTVCollectionViewCell.h"
#import "ListenDataSongsModel.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
@interface TheBestHotTVCollectionViewCell ()
//背景图片
@property(nonatomic, retain) UIView *backView;
//图片
@property(nonatomic, retain) UIImageView *picUrlImageView;
//排序1
@property(nonatomic, retain) UILabel *queueOneLabel;
//排序2
@property(nonatomic, retain) UILabel *queueTowLabel;
//排序3
@property(nonatomic, retain) UILabel *queueThreeLabel;
//歌名1
@property(nonatomic, retain) UILabel *nameOneLabel;
//歌名2
@property(nonatomic, retain) UILabel *nameTowLabel;
//歌名3
@property(nonatomic, retain) UILabel *nameThreeLabel;

@end
@implementation TheBestHotTVCollectionViewCell
- (void)dealloc {
    [_backView release];
    [_picUrlImageView release];
    [_queueOneLabel release];
    [_queueThreeLabel release];
    [_nameOneLabel release];
    [_nameTowLabel release];
    [_nameThreeLabel release];
    [_listenDataModel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // 创建视图
        [self createSubVeiw];
    }
    return self;
}
#pragma mark 创建视图
-(void)createSubVeiw {
    //大背景图片
    self.backView = [[UIView alloc]init];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.backView.alpha = 0.05;
    [self.contentView addSubview:self.backView];
    [self.backView release];
   //图片
    self.picUrlImageView = [[UIImageView alloc]init];
//    self.picUrlImageView.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.picUrlImageView];
    [self.picUrlImageView release];
    
    //排序1
    self.queueOneLabel = [[UILabel alloc]init];
//    self.queueOneLabel.backgroundColor = [UIColor orangeColor];
    self.queueOneLabel.textColor = [UIColor redColor];
    self.queueOneLabel.textAlignment = NSTextAlignmentCenter;
    self.queueOneLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:17];
    [self.contentView addSubview:self.queueOneLabel];
    [self.queueOneLabel release];
    
    //排序2
    self.queueTowLabel = [[UILabel alloc]init];
//    self.queueTowLabel.backgroundColor = [UIColor yellowColor];
    self.queueTowLabel.textColor = [UIColor orangeColor];
    self.queueTowLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:17];
    self.queueTowLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.queueTowLabel];
    [self.queueTowLabel release];
    
    //排序3
    self.queueThreeLabel = [[UILabel alloc]init];
//    self.queueThreeLabel.backgroundColor = [UIColor cyanColor];
    self.queueThreeLabel.textColor = [UIColor yellowColor];
    self.queueThreeLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:17];
    self.queueThreeLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.queueThreeLabel];
    [self.queueThreeLabel release];
    
    //歌名1
    self.nameOneLabel = [[UILabel alloc]init];
//    self.nameOneLabel.backgroundColor = [UIColor purpleColor];
    self.nameOneLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameOneLabel];
    [self.nameOneLabel release];
    
    //歌名2
    self.nameTowLabel = [[UILabel alloc]init];
//    self.nameTowLabel.backgroundColor = [UIColor redColor];
    self.nameTowLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameTowLabel];
    [self.nameTowLabel release];
    
    //歌名3
    self.nameThreeLabel = [[UILabel alloc]init];
//    self.nameThreeLabel.backgroundColor = [UIColor cyanColor];
    self.nameThreeLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameThreeLabel];
    [self.nameThreeLabel release];
    
}
#pragma mark 设置大小
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    //背景图片
    self.backView.frame = CGRectMake(10, 5, self.frame.size.width - 20, self.frame.size.height - 10);
    //图片
    self.picUrlImageView.frame = CGRectMake(10, 5, self.frame.size.width / 3, self.frame.size.height - 10);
    //排序1
    self.queueOneLabel.frame = CGRectMake(self.picUrlImageView.frame.origin.x + self.picUrlImageView.frame.size.width + 5, self.picUrlImageView.frame.origin.y, 20, self.picUrlImageView.frame.size.height / 3);
    //歌名1
    self.nameOneLabel.frame = CGRectMake(self.queueOneLabel.frame.size.width + self.queueOneLabel.frame.origin.x, self.queueOneLabel.frame.origin.y, self.frame.size.width - self.picUrlImageView.frame.size.width - self.picUrlImageView.frame.origin.x - self.queueOneLabel.frame.size.width - 15, self.queueOneLabel.frame.size.height);
    //排序2
    self.queueTowLabel.frame = CGRectMake(self.queueOneLabel.frame.origin.x, self.queueOneLabel.frame.size.height, self.queueOneLabel.frame.size.width, self.queueOneLabel.frame.size.height);
    //歌名2
    self.nameTowLabel.frame = CGRectMake(self.nameOneLabel.frame.origin.x, self.queueTowLabel.frame.origin.y, self.nameOneLabel.frame.size.width, self.queueTowLabel.frame.size.height);
    //排序3
    self.queueThreeLabel.frame = CGRectMake(self.queueTowLabel.frame.origin.x, self.queueOneLabel.frame.size.height * 2, self.queueTowLabel.frame.size.width, self.queueTowLabel.frame.size.height);
    //歌名3
    self.nameThreeLabel.frame = CGRectMake(self.nameTowLabel.frame.origin.x, self.queueThreeLabel.frame.origin.y, self.nameTowLabel.frame.size.width, self.queueThreeLabel.frame.size.height);
}
#pragma mark 重写listenDataModel的setter方法
- (void)setListenDataModel:(ListenDataModel *)listenDataModel {
    if (_listenDataModel != listenDataModel) {
        [_listenDataModel release];
        _listenDataModel = [listenDataModel retain];
    }
    //图片
    [self.picUrlImageView sd_setImageWithURL:[NSURL URLWithString:listenDataModel.picUrl]];
    self.queueOneLabel.text = @"1";
    self.queueTowLabel.text = @"2";
    self.queueThreeLabel.text = @"3";
    ListenDataSongsModel *modelOne = listenDataModel.songArray[0];
    ListenDataSongsModel *modelTow = listenDataModel.songArray[1];
    ListenDataSongsModel *modelThree = listenDataModel.songArray[2];
    //第一个
    if ((modelOne.name.length + modelOne.singerName.length) * 13 > self.nameOneLabel.frame.size.width) {
        self.nameOneLabel.text = modelOne.name;
    }else {
        self.nameOneLabel.text = [NSString stringWithFormat:@"%@ -%@", modelOne.name, modelOne.singerName];
    }
    //第二个
    if ((modelTow.name.length + modelTow.singerName.length) * 13 > self.nameOneLabel.frame.size.width) {
        self.nameTowLabel.text = modelTow.name;
    }else {
        self.nameTowLabel.text = [NSString stringWithFormat:@"%@ -%@", modelTow.name, modelTow.singerName];
    }
    //第三个
    if ((modelThree.name.length + modelThree.singerName.length) * 13 > self.nameOneLabel.frame.size.width) {
        self.nameThreeLabel.text = modelThree.name;
    }else {
        self.nameThreeLabel.text = [NSString stringWithFormat:@"%@ -%@", modelThree.name, modelThree.singerName];
    }
}
@end
